﻿using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System;
using UnityEngine.SocialPlatforms;
//using GoogleMobileAds.Api;

public class AdsControl : MonoBehaviour
{


	protected AdsControl ()
	{
	}

	private static AdsControl _instance;

	//InterstitialAd interstitial;
	//BannerView bannerView;

	public string AdmobID_Android_Interstitial, AdmobID_IOS_Interstitial, AdmobID_Android_Banner, AdmobID_IOS_Banner;

	public static AdsControl Instance { get { return _instance; } }

	void Awake ()
	{

		if (FindObjectsOfType (typeof(AdsControl)).Length > 1) {
			Destroy (gameObject);
			return;
		}

		_instance = this;
		MakeNewInterstial ();
		RequestBanner ();
		ShowBanner ();

		DontDestroyOnLoad (gameObject); //Already done by CBManager

	}


	public void HandleInterstialAdClosed (object sender, EventArgs args)
	{


		//if (interstitial != null)
		//	interstitial.Destroy ();
		MakeNewInterstial ();



	}

	void MakeNewInterstial ()
	{


		#if UNITY_ANDROID
		interstitial = new InterstitialAd (AdmobID_Android_Interstitial);
		#endif
		#if UNITY_IPHONE
		interstitial = new InterstitialAd (AdmobID_IOS_Interstitial);
		#endif
		//interstitial.OnAdClosed += HandleInterstialAdClosed;
		//AdRequest request = new AdRequest.Builder ().Build ();
		//interstitial.LoadAd (request);

	}


	public void showAds ()
	{

			//interstitial.Show ();

	}



	private void RequestBanner ()
	{

		string adUnitId = "";

		#if UNITY_ANDROID
		adUnitId = AdmobID_Android_Banner;
		#endif
		#if UNITY_IPHONE
		adUnitId = AdmobID_IOS_Banner;
		#endif
		// Create a 320x50 banner at the top of the screen.
		//bannerView = new BannerView (adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
		//// Load a banner ad.
		//AdRequest request = new AdRequest.Builder ().Build ();
		//bannerView.LoadAd (request);
	}

	public void ShowBanner ()
	{
		//bannerView.Show ();
	}


}

